/**
 * @file        Target.ts
 * @author      shenyc
 * @date        2021-08-10
 * @copyright   Copy right (c) shenyc (shenyczz@163.com).
 *              All rights reserved.
 *
 ******************************************************************************/
// {{@@@}}
"use strict";
import * as utils from "../utils";
// ----------------------------------------------------------------------------
/**
 * Target
 * @author shenyc
 * @description 根类
 * @param {any} [options] 选项
 */
export abstract class Target extends Object {
    //
    protected constructor(options?: any) {
        super(options);

        this._uid = this.create_uuid();
        this._name = this.constructor.name;
        this._className = this.constructor.name;
        this._options = Object.assign({}, options);
    }

    /**
     * 本级唯一标识 (uid), 只读属性
     */
    private _uid: string = "uid not set";
    public get uid() {
        return this._uid;
    }

    /**
     * 父级id标识, 一般图层管理中使用
     */
    private _pid: string = "";
    public get pid() {
        return this._pid;
    }
    public set pid(pid: string) {
        this._pid = pid;
    }

    /** 名称 */
    private _name: string;
    public getName(): string {
        return this._name;
    }
    public setName(val: string): void {
        this._name = val;
    }

    /** 类名 */
    private readonly _className: string;
    public getClassName() {
        return this._className;
    }

    /** 选项 */
    private _options: any;
    public getOptions() {
        return this._options;
    }
    public setOptions(options: any) {
        Object.assign(this._options, options);
        const opts = this.getOptions() as any;
        if (opts.hasOwnProperty("name")) {
            this.setName(opts["name"]);
        }
        this.onOptionsChanged(this.getOptions());
    }
    protected onOptionsChanged(_val: any) {
        // no body
    }

    /** 可见 */
    private _visible: boolean = true;
    public get visible(): boolean {
        return this.getVisible();
    }
    public set visible(visible: boolean) {
        this.setVisible(visible);
    }
    public getVisible(): boolean {
        return this._visible;
    }
    public setVisible(visible: boolean) {
        let newValue = visible;
        let oldValue = this.getVisible();
        this._visible = visible;
        this.onVisibleChanged(newValue, oldValue);
    }
    protected onVisibleChanged(_newValue: boolean, _oldValue: boolean) {
        // no body
    }

    /**
     * 创建 UUID
     * @returns uid as string
     */
    private create_uuid = (): string => utils.createGuid();

    // ----------------------------------------------test
    // 静态变量

    // Symbol
    public static symbol_1 = Symbol(10);
    public static symbol_2 = Symbol("10");

    // {{END}}
}

export namespace Target {
    export type ConstructorOptions = {
        x: symbol;
        x2: string;
    };
}

export default Target;
// ----------------------------------------------------------------------------
// {{@@@}}
